#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "DevicesTime.h"
#include "cpuusage.h"

/* CPU 使用率 */
float g_fCPUUsage = 0.0f;

void vCPUUsageIdleHook(void)
{
    static uint32_t st_uiCountMax = 0;
    int64_t lTickStop = lTimebaseGet() + 200000LL;
    uint32_t uiTickNow;

    for(uiTickNow = 0; lTimebaseGet() < lTickStop; ++uiTickNow);

    st_uiCountMax = st_uiCountMax < uiTickNow ? uiTickNow : st_uiCountMax;

    /* get CPU usage */
    g_fCPUUsage = (float)(st_uiCountMax - uiTickNow) / (float)st_uiCountMax;
}

float fCPUUsageGet(void)
{
    return g_fCPUUsage;
}
